<%--
  Created by IntelliJ IDEA.
  User: 22541
  Date: 2022/4/11
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>已选课程</title>
</head>
<body>
<h2 align="center">已选课程</h2>
<h4 align="center">学号：${user.id}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名：${user.username}</h4>
<%--<form action="DelController" method="post">--%>
<table border="1" cellspacing="0" width="80%" align="center">
    <%--表头--%>
    <tr>
        <th></th>
        <th>序号</th>
        <th>课程名称</th>
        <th>分数</th>
    </tr>

    <c:forEach items="${AllCourseHit}" var="hitcourse" varStatus="status">
        <tr align="center">
            <td><input type="checkbox" class="cb" id="${hitcourse.cId}" name="checkbox" value="${hitcourse.cId}"></td>
<%--            <td>${hitcourse.id}</td>--%>
            <td>${status.count}</td>
            <td>${hitcourse.cName}</td>
            <td>${hitcourse.score}</td>

        </tr>

    </c:forEach>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div align="center"><input type="button" value="退选" id="exit" align="center">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="CourseController?operation=all"><input type="button" value="课程管理" align="center"></a></div>


<%--</form>--%>
<script>
    // document.getElementById("del").
    document.getElementById("exit").onclick = function(){        //点击"退选"调用函数
        let result = "";
        let count = 0;
        let inputs = document.getElementsByTagName("input");
        for(let i = 0;i < inputs.length;i++){
            if(inputs[i].type === "checkbox" && inputs[i].checked){  //如果被选中
                result += inputs[i].value + ",";
                count++;
            }
        }
        if(count !== 0) {
            result = result.substring(0,result.lastIndexOf(','));
            window.location.href= "CourseController?operation=exit&tag="+result;
        }else{
            alert("请选择要退选的课！");
        }
    }
</script>
</body>
</html>
